// 存储用户信息到仓库
import { defineStore } from 'pinia'
import { getMyUserInfo } from '@/api/user'

const useUserInfo = defineStore('userInfo', {
    state: () => {
        return {
            avatar: '', // 头像
            sex: 0, // 性别
            sign: '', // 简介
            name: '', // 姓名
            password: '', // 密码
            secretAnswer: ''
        }
    },
    actions: {
        setUserInfo(data) {
            this.avatar = data.avatar
            this.sex = data.sex
            this.sign = data.sign
            this.name = data.name
            this.password = data.password
        },
        async getUserInfo() {
            // 拿去用户信息
            let data = (await getMyUserInfo()).data
            this.avatar = data.avatar
            this.sex = data.sex
            this.sign = data.sign
            this.name = data.name
        },
        setPasswordA(data) {
            this.password = data.password
            this.secretAnswer = data.secretAnswer
        }
    }
})


export default useUserInfo